#include "test_iomux.h"
#include "cm_demo_uart.h"
#include "cm_iomux.h"
#include "string.h"
#include "stdlib.h"




void cm_test_iomux_operation(unsigned char *cmd[],int len)
{
    if(0 == strncmp("SET_PIN_FUNC",cmd[2],strlen("SET_PIN_FUNC")))
    {
        int32_t pin = strtoul(cmd[3],(void**)0,10);
        int32_t fun = strtoul(cmd[4],(void**)0,10);
        int32_t iomux_set_pin_func = cm_iomux_set_pin_func(pin, fun);
        cm_demo_printf("set pin func ret: %d\n",iomux_set_pin_func);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,iomux_set_pin_func,cm_iomux_set_pin_func);
    }else if(0 == strncmp("GET_PIN_FUNC",cmd[2],strlen("GET_PIN_FUNC")))
    {
        int32_t pin = strtoul(cmd[3],(void**)0,10);
        int32_t fun = 0;
        int32_t iomux_get_pin_func = cm_iomux_get_pin_func(pin,&fun);
        cm_demo_printf("get pin func ret(fun): %#x\n",iomux_get_pin_func);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,iomux_get_pin_func,cm_iomux_get_pin_func);
        cm_demo_printf("pin: %d, fun: %d\n",pin,fun);
    }else if(0 == strncmp("SET_PIN_CMD",cmd[2],strlen("SET_PIN_CMD")))
    {
        cm_iomux_pin_e pin = atoi(cmd[3]); 
        cm_iomux_pincmd_e cmd_e = atoi(cmd[4]); 
        uint8_t cmd_arg = atoi(cmd[5]);
        int32_t iomux_set_pin_cmd = cm_iomux_set_pin_cmd(pin,cmd_e,cmd_arg);
        cm_demo_printf("cm_iomux_set_pin_cmd ret:%d\n",iomux_set_pin_cmd);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,iomux_set_pin_cmd,cm_iomux_set_pin_cmd);
    }
    else if(0 == strncmp("SET_GET_FUNC",cmd[2],strlen("SET_GET_FUNC")))
    {
        int32_t pin = strtoul(cmd[3],(void**)0,10);
        int32_t fun = strtoul(cmd[4],(void**)0,10);
        int32_t iomux_set_pin_func = cm_iomux_set_pin_func(pin, fun);
        cm_demo_printf("set pin func ret: %d\n",iomux_set_pin_func);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,iomux_set_pin_func,cm_iomux_set_pin_func);

        int32_t get_fun = 0;
        int32_t iomux_get_pin_func = cm_iomux_get_pin_func(pin,&get_fun);
        cm_demo_printf("get pin func ret(fun): %#x\n",iomux_get_pin_func);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,iomux_get_pin_func,cm_iomux_get_pin_func);
        cm_demo_printf("pin: %d, fun: %d\n",pin,get_fun);
    }
    else{
        cm_demo_printf("param error!\n");
    }
}

